ATM Central Server
In this example the ATM Central Server (atmcs) interacts with the
ATM clients and relays transaction requests to individual banks.
The interface design follows the object factory pattern . This example
demonstrates how to:
-
Design interfaces using the object factory pattern
-
Use an interface as a servant class
-
Implement interfaces as both server and client
-
Manage CORBA objects with a hash table
-
Connect to objects in the persistent layer
-
Handle transactions within synchronized blocks
-
Use mutliple threads to handle access to the persistent layer from clients
and the console terminal.
This server must be used together with the Bank
Server. Since this implementation has both interface layer objects
and persistent objects, you need both VisiBroker (link)
and PsePro (link).
Source Files
-
atmcs.idl
IDL file for the interfaces SessionIF and SessionMgrIF in the bank
module. (IF stands for interface.) Also defined are exception
"AtmcsError", a cash card data structure CardInfo, and an account information
structure AccountInfo.
SessionMgrIF only has login and logout operations
exposed, though the implementation class may have convential object management
operations.
-
Server.java
The Server code, which has a main function that creates an instance
of the SessionMgrImpl class and calls impl_is_ready()
(via a separate thread class BoaThread) to make it available to the client.
The code also defines a thread class TerminalThread, which is used to run
a console session for direct access to the database by an administrator
(a login password "atmcs" is needed). Another similar thread may
also be started to process commands from an input command file if it is
present. To shutdown the server, type in "shutdown" from the console.
The Server code contains the following interface implementation classes:
-
SessionMgrImpl
Implementation for the session manager interface "SessionMgrIF". It
implements access control methods: login and logout.
Mangement methods like remove (removes a session), and showSessions
are implemented but not exposed as interface operations.
This class contains a link to its persistent counterpart ATMManager.
If that link is not null, it will retrieve bank and card information from
the database during login. It then connects to the correct bank server
to finish the login process. A persistent Session object will
also be created to keep records of transactions in this session.
The session ends when logout is invoked.
-
SessionImpl
Implementation for the interface "SessionIF". It implements
get methods: getBalance, getAccountInfo, getAccountHistory, and
transaction methods: deposit, withdraw, transferTo, payBill.
Each session is created with an AccountIF object as one of the input
arguments. AccountIF thus serves as a servant object. All interface
methods invoke the corresponding methods on this servant object.
This class contains a link to its persistent counterpart Session.
If that link is not null, it will log all transactions to that the persistent
Session object using the logTrx() method.
Note that all transactions appear inside a synchronized block. This
is necessary for multi-thread operation.
-
Client.java
The client code. It binds to the SessionMgrImpl object
using a server name (e.g. "ATM Session Manager"). It then waits for
user commands to open accounts and to initiate transactions. The
runTerminal method translates command line inputs into method calls to
the server. One may also run the client with an input text file that
contains multiple command lines. An example is in Test1.txt.
Batch Files
-
setEnv.bat
A batch file for setting the environment variables.
-
build.bat
A batch file for building the client and server on Windows.
It will first invoke the IDL compiler and then compile the server and client
source codes. A subdirectory named "bank" will be created, which
contains the CORBA stub and skeleton codes and their corresponding class
files.
-
runsrv.bat
A batch file for running the server. The command line format is:
runsrv [database_file.odb] [command.txt]
If the optional database file is not specified, it simply runs without
connection to the persistent layer.
If the database file is specified, it will open it and use the information
therein. Also, a terminal thread is started to process input command
from the console.
If command.txt is specified, it will start a separate thread
to process the input commands in the file. An example is in bankData.txt.
client.bat
A batch file for running the client. The command line format
is:
client [hostname] [command.txt]
where the optional hostname (or IP address) is where the server is running
and command.txt is an optional input command file such as Test1.txt.
Running the Codes
This example was developed under VisiBroker (link).
To run the codes, make sure that the VisiBroker Smart Agent (osagent) is
running on the server object's network. Also, the Bank
Server needs to be running since it process bank transactions.
(You need to put some bank account information into the bank server too.
Use the Test1.txt command file in the bank directory.) Then enter
the commands:
On Windows:
start runsrv atmcs.odb bankdata.txt
client (or client [hostname] [Test1.txt])
On Unix:
vbj Server atmcs.odb bankdata.txt &
vbj Client (or vbj Client [hostname] [Test1.txt])
From the console client, you may do for example:
login 88881001 Jane 888
You may find the card numbers by typing in "showcard" from the atmcs
Server. You may find bank account information from the file Test1.txt
under the bank directory.
Alternatively, you may use the runall.bat
file to start both the Bank Server and the atmcs Server. Be
sure to wait for the servers to come up (".... is ready") before going
over the pauses. The bank client window will close after finishing
putting data to the bank server.